<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../../query.header.jsp"%>
<style type="text/css">
#_body {
	background: #FFFFFF url() repeat-x;
}
</style>

<script type="text/javascript">

var _roleId = "${param.roleId}";

var _userList;
$("#_userList").ready(function() {
	_userList = $("#_userList").jslist({
		core: {
			listUrl:ctx+"/biz/system/user/unbind/list.json",
			countUrl:ctx+"/biz/system/user/unbind/count.json",
			queryParams: {"roleId":_roleId},
			columnMetadatas:[{width:100,title:"名称",name:"name"},
							{width:80,title:"电话",name:"mobile"},
							{width:80,title:"账号",name:"account"},
							{width:100,title:"建设单位",name:"organName"},
							{title:"描述",name:"description"}]},
		title:{ title:"未绑定用户列表",titleType:"gridHeader"},
		selectable: {selectType:"checkbox"},
		plugins:["title","filter","selectable"]
	}).jslist("refresh");
});

function _beforeConfirm(callback) {
	var selectedItems = _userList.jslist("getSelectedItems");
	if (selectedItems.length == 0) {
		$.alert("请选择用户！");
		return false;
	}

	var _userIds = $(selectedItems).map(function(i,item){
		return item.id;
	}).get().join(",");

	var result = true;
	
	$.ajax({
		type: "POST",
		url: ctx+"/biz/system/role/bindUser.json",
		data: {"roleId":_roleId,
			"userIds":_userIds},
		dataType: "json",
		async: false,
		success: function(data){
			if (!data.succeed) {
				$.alert(data.message);
				return result = false;
			}
			result = true;	
		},
		error:function(message){
			$.alert(message);
			result = false;
		}
	});

	if (result == false) {
		return false;
	}
	
	try {
		callback();
		return true;
	}
	catch(error) {
		return false;
	}
}
 
</script>

<body>

<div id="_userList" class="span9">
</div>

</body>
</html>